Travel Planning Agent with Couchbase Vector Search, Gemini 2.0 Flash and OpenAI

工作流概述

这是一个包含13个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "iGAzT789R7Q1fOOE",
  "meta": {
    "instanceId": "7a1e9dd164c758cbdeb7cf88274e567a937a36ed99d4d22ff24b645841097c48",
    "templateId": "3577",
    "templateCredsSetupCompleted": true
  },
  "name": "Travel Planning Agent with Couchbase Vector Search, Gemini 2.0 Flash and OpenAI",
  "tags": [],
  "nodes": [
    {
      "id": "0f361616-a552-43ed-9754-794780113955",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        380,
        240
      ],
      "webhookId": "c22b2240-ff07-44e5-a1aa-63584150a1cb",
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "e8b9815d-0fe5-4e7c-a20b-1602384580cd",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        560,
        480
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.0-flash"
      },
      "typeVersion": 1
    },
    {
      "id": "a4b15997-de4d-4c78-b623-e936442134af",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1260,
        280
      ],
      "parameters": {
        "color": 3,
        "width": 800,
        "height": 500,
        "content": "## AI Travel Agent Powered by Couchbase.

### You will need to:
1. Setup your Google API Credentials for the Gemini LLM
2. Setup your OpenAI Credentials for the OpenAI embedding nodes.
3. Create a Couchbase cluster (using [Couchbase Capella](https://cloud.couchbase.com/) in the cloud, or Couchbase Server)
4. Add [Database credentials](https://docs.couchbase.com/cloud/clusters/manage-database-users.html#create-database-credentials) with appropriate permissions for the operations you want to perform
5. Configure [Allowed IP addresses](https://docs.couchbase.com/cloud/clusters/allow-ip-address.html) for your n8n instance. Use `0.0.0.0/0` for easier testing.
6. Create a bucket, scope, and collection. We recommend the following:
   - Bucket: `travel-agent`
   - Scope: `vectors`
   - Collection: `points-of-interest`
7. Navigate to the Data Tools, click the Search tab, and click Import Search Index. Upload the following JSON file found [here](https://gist.github.com/ejscribner/6f16343d4b44b1af31e8f344557814b0).


Once all of that is configured you will need to send the loading webhook with some data points (see example).

This should create vectorized data in  `points-of-interest` collection.

Once you have data points there try to ask the Agent questions about the data points and test the response. Eg. \"Where should I go for a romantic getaway?\""
      },
      "typeVersion": 1
    },
    {
      "id": "34866f8e-00b0-4706-82d7-491b9531a8b6",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        800,
        1000
      ],
      "webhookId": "3ca6fbdd-a157-4e9d-9042-237048da85b6",
      "parameters": {
        "path": "3ca6fbdd-a157-4e9d-9042-237048da85b6",
        "options": {
          "rawBody": true
        },
        "httpMethod": "POST"
      },
      "typeVersion": 2
    },
    {
      "id": "26d4e62a-42b0-4e09-8585-827e5bcc9fff",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        1180,
        1360
      ],
      "parameters": {
        "options": {},
        "jsonData": "={{ $json.body.raw_body.point_of_interest.title }} - {{ $json.body.raw_body.point_of_interest.description }}",
        "jsonMode": "expressionData"
      },
      "typeVersion": 1
    },
    {
      "id": "63fc308f-4d1c-4d24-9b20-68d7e6c2dbba",
      "name": "Recursive Character Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        1280,
        1540
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "84f8c32b-8e0c-457c-aaec-17827042674d",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -60,
        1060
      ],
      "parameters": {
        "width": 720,
        "height": 460,
        "content": "## CURL Command to Ingest Data.

Here is an example of how you can load data into your webhook once its active and ready to get requests.

```
curl -X POST \"webhook url\" \
  -H \"Content-Type: application/json\" \
  -d '{
    \"raw_body\": {
      \"point_of_interest\": {
        \"title\": \"Eiffel Tower\",
        \"description\": \"Iconic iron lattice tower located on the Champ de Mars in Paris, France.\"
      }
    }
  }'
```

(replace webhook url with the URL listed in the webhook node)

A shell script to bulk insert six data points can be found [here](https://gist.github.com/ejscribner/355a46a0a383a4878e65e2230b92c6b5). Be sure to activate the workflow and use the production Webhook URL when running the script."
      },
      "typeVersion": 1
    },
    {
      "id": "b2cf8788-849c-4420-b448-bd49caa4941e",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        720,
        480
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "0bf7fef9-f999-42a8-a6a8-ab111fe9a084",
      "name": "AI Travel Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        600,
        240
      ],
      "parameters": {
        "options": {
          "maxIterations": 10,
          "systemMessage": "You are a helpful assistant for a trip planner. You have a vector search capability to locate points of interest, Use it and don't invent much."
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "3af3c8ce-582b-407c-847a-8063f9ad2e1a",
      "name": "Retrieve docs with Couchbase Search Vector",
      "type": "n8n-nodes-couchbase.vectorStoreCouchbaseSearch",
      "position": [
        860,
        500
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": 10,
        "options": {},
        "toolName": "PointofinterestKB",
        "embedding": "embedding",
        "textFieldKey": "description",
        "couchbaseScope": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "couchbaseBucket": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "toolDescription": "The list of Points of Interest from the database.",
        "vectorIndexName": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "couchbaseCollection": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "77a4e857-607a-4bbc-a28d-8a715f9415d5",
      "name": "Insert docs with Couchbase Search Vector",
      "type": "n8n-nodes-couchbase.vectorStoreCouchbaseSearch",
      "position": [
        1100,
        1120
      ],
      "parameters": {
        "mode": "insert",
        "options": {},
        "embedding": "embedding",
        "textFieldKey": "description",
        "couchbaseScope": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "couchbaseBucket": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "vectorIndexName": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "embeddingBatchSize": 1,
        "couchbaseCollection": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "4c0274c3-6647-4f45-b7d4-d63cfe2102ea",
      "name": "Generate OpenAI Embeddings using text-embedding-3-small",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        960,
        740
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "83f864fa-a298-4738-a102-ca2d283377de",
      "name": "Generate OpenAI Embeddings using text-embedding-3-small1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        1000,
        1340
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.2
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "callerPolicy": "workflowsFromSameOwner",
    "executionOrder": "v1"
  },
  "versionId": "80e40e5a-35a3-4fa4-b90e-ac9d76897bbd",
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Insert docs with Couchbase Search Vector",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Travel Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Insert docs with Couchbase Search Vector",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Travel Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Travel Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "Retrieve docs with Couchbase Search Vector": {
      "ai_tool": [
        [
          {
            "node": "AI Travel Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Generate OpenAI Embeddings using text-embedding-3-small": {
      "ai_embedding": [
        [
          {
            "node": "Retrieve docs with Couchbase Search Vector",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Generate OpenAI Embeddings using text-embedding-3-small1": {
      "ai_embedding": [
        [
          {
            "node": "Insert docs with Couchbase Search Vector",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • @N8N/N8N Nodes Langchain.Chattrigger
  • @N8N/N8N Nodes Langchain.Lmchatgooglegemini
  • Stickynote
  • Webhook
  • @N8N/N8N Nodes Langchain.Documentdefaultdataloader

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作